<?php
use Workerman\Worker;
use Workerman\Events\EventInterface;
require_once __DIR__ . '/Workerman/Autoloader.php';

$worker = new Worker('text://0.0.0.0:888');
$worker->onConnect = function($con){
    echo "IP " . $con->getRemoteIp() . "连接成功 \n";
};

$worker->onMessage = function($con,$data){

    $client = $con->getRemoteIp();
    $data = mb_convert_encoding($data,'UTF-8');
        echo $client . '发来消息: ' . $data . "\n";
    $con->send('recevie success' . "\n");
};

$worker->onClose = function ($con){
    $client = $con->getRemoteIp();
    echo $client . ' 断开.' . "\n";

};

$worker->onError = function($con,$code,$msg){
    echo "error $code $msg \n";
};


Worker::runAll();